package com.producer.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.support.TransactionSynchronizationManager;

@Service
public class TestService {

    @Autowired
    LogService logService;

    @Transactional(propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
    public void executeService(int type){

        System.out.println("执行业务逻辑");


        /*System.out.println("业务执行完成");
        if (!TransactionSynchronizationManager.isSynchronizationActive()) {
            // 调用异步方法发送日志
            System.out.println("事务未开启");
        }else{
            System.out.println("事务已开启");
        }*/

        logService.sendLogAsync();
    }

    public void executeServiceNoTranscational(int type){
        System.out.println("业务执行完成");
        if (!TransactionSynchronizationManager.isSynchronizationActive()) {
            // 调用异步方法发送日志
            System.out.println("事务未开启");
        }else{
            System.out.println("事务已开启");
        }
        logService.sendLogAsync();
    }
}
